/**
 * Created by Administrator on 2017/4/5.
 */

//检查个人用户登录
function checkPersonal(oForm){
    var username = str_trim($(oForm).find('#username').val());
    if(username == ''){
        layer.msg("用户名/手机号码不能为空!",{icon:5,time:2000});
        $(oForm).find('#username').focus();
        $(oForm).find('#username').val(username);
        return false;
    }
    if($(oForm).find('#password').val() == '' ||  $(oForm).find('#password').val().length < 6  ){
        layer.msg("密码不能为空,或者密码长度不能少于6位!",{icon:5,time:2000});
        $(oForm).find('#password').focus();
        return false;
    }
    var queryString = $(oForm).formSerialize();
    $.ajax({
        url: '/personal/ajax_login',
        dataType: "json",
        data: queryString,
        type: "POST",
        success: function (data) {
            if(data.status == '0'){
                layer.msg(data.msg, {icon: 6});
                location = welcomeUrl;
            }else{
                layer.msg(data.msg, {icon: 5});
            }
        },
        error: function (data) {
            var msgErr='';
            var errors = $.parseJSON(data.responseText);
            $.each(errors, function(index, value) {
                msgErr +=  value+";<br>";
            });
            layer.msg(msgErr, {icon: 5});
        },
        complete: function () {
        }
    });
    return false;
}

//检查企业用户登录
function checkCompany(oForm){
    var username = str_trim($(oForm).find('#username').val());
    if(username == ''){
        layer.msg("用户名不能为空!",{icon:5,time:2000});
        $(oForm).find('#username').focus();
        $(oForm).find('#username').val(username);
        return false;
    }
    if($(oForm).find('#password').val() == '' ||  $(oForm).find('#password').val().length < 6  ){
        layer.msg("密码不能为空,或者密码长度不能少于6位!",{icon:5,time:2000});
        $(oForm).find('#password').focus();
        return false;
    }
    var queryString = $(oForm).formSerialize();
    $.ajax({
        url: '/company/ajax_company_login',
        dataType: "json",
        data: queryString,
        type: "POST",
        success: function (data) {
            if(data.status == '0'){
                layer.msg(data.msg, {icon: 6});
                location = companyWelcomeUrl;
            }else{
                layer.msg(data.msg, {icon: 5});
            }
        },
        error: function (data) {
            var msgErr='';
            var errors = $.parseJSON(data.responseText);
            $.each(errors, function(index, value) {
                msgErr +=  value+";<br>";
            });
            layer.msg(msgErr, {icon: 5});
        },
        complete: function () {
        }
    });
    return false;
}
